# aem.two_d.single.head_well -- Head-specified wells

import copy

import well

import geometry

import aem.matrix

class HeadWell(well.Well):
	'''Class for head-specified wells

	Python call: HeadWell(xc,yc,radius,specifiedHead=0.0,
	                      parent=None,controlPoints=None)

	Attributes:

	  - xc,yc: location of well (inherited from Circle)
	  - radius: radius of well (inherited from Circle)
	  - parent: parent of the element (inherited from Element)
	  - parameters: ColumnList of strength parameters, set to 0 
	  - solver: solver (inherited from Element)
	  - elementList: list of elements, defaults to itself (inherited from Element)
	  - __numberOfParameters: number of parameters, set to 1 (inherited from Well)
	  - specifiedHead: head specified at well radius
	  - controlPoints: list of control points, optional, set to right side of well radius

	Overloaded methods from Well and Element:
	__init__, getMatrixCoefficients, getMatrixContribution, check
	'''

	def __init__(self,xc=0.0,yc=0.0,rw=0.0,specifiedHead=0.0,parent=None,
		     controlPoints=None):
		'''Constructor'''
		well.Well.__init__(self,xc,yc,rw,0.0,parent)
		self.specifiedHead = specifiedHead
		self.givenElement = 0
		if controlPoints:
			self.controlPoints = copy.copy(controlPoints)
		else:
			self.controlPoints = [ self.center + geometry.XY(self.radius,0) ]

	def __repr__(self):
		# Parent not yet included
		return 'HeadWell' + str((self.center.x,self.center.y,self.radius,self.specifiedHead))	

	def getMatrixCoefficients(self,fa,ctlPt):
		return fa(self,ctlPt)

	def getMatrixContribution(self,elementList):
		rows = []
		columns = [ aem.matrix.MatrixColumn(self,0) ]
		for cp in self.controlPoints:
			mr = aem.matrix.MatrixRow()
		for e in elementList:
			mr.A = mr.A + e.getMatrixCoefficients(lambda z,p:z.potentialInfluence(p),cp)
			mr.b = self.headToPotential(cp,self.specifiedHead) - self.potential(cp)
			rows.append(mr)
		return ( rows,columns )

	def check(self):
		rv = []
		for cp in self.controlPoints:
			rv.append(self.head(cp) - self.specifiedHead)
		return rv
